
local M = {}
M.new = function (ctx, initParam)
    local handler = function (ws, req, ctx)
        local count = 0
        local Echo = {}
        Echo.onOpen = function ()
            print("websocket opened")
        end
        Echo.onMessage = function (msg)
            print(msg)
            ws.send("your message: " .. msg)
            count = count + 1
            if 5 == count then
                ws.close()
            end
        end
        Echo.onClose = function ()
            print("websocket closed")
        end
        Echo.onError = function ()

        end
        return Echo
    end
    return handler
end

local moduleName = ...
_G[moduleName] = M
complex = M
return complex